/*
 * Copyright 2011 Clean GWT
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software distributed under the License
 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
 * or implied. See the License for the specific language governing permissions and limitations under
 * the License.
 */
package com.cleangwt.bootstrap.client.ui;

import com.cleangwt.uibinder.client.TemplateSupport;
import com.google.gwt.dom.client.DivElement;
import com.google.gwt.dom.client.Document;
import com.google.gwt.dom.client.Element;
import com.google.gwt.dom.client.ParagraphElement;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.Widget;

/**
 * 
 * 
 * @author Jess
 * @version 1.0
 * @since 1.0
 * @see http://getbootstrap.com/components/#jumbotron
 */
public class Jumbotron extends SimplePanel {

  private static final String DEFAULT_STYLENAME = "jumbotron";

  /**
   * Creates a jumbotron that wraps an existing &lt;div&gt; element of template.
   * 
   * @param template the template
   * @param element the element to be wrapped
   */
  public static Jumbotron wrap(TemplateSupport template, Element element) {
    Jumbotron widget = new Jumbotron(element);
    template.wrap(widget);
    return widget;
  }

  private Element container = Document.get().createDivElement();

  /**
   * This constructor may be used by subclasses to explicitly use an existing element. This element
   * must be a &lt;div&gt; element.
   * 
   * @param element the element to be used
   */
  protected Jumbotron(Element element) {
    assert element.getTagName().equalsIgnoreCase(DivElement.TAG);
    this.setElement(element);
  }

  /**
   * Creates a jumbotron.
   */
  public Jumbotron(String header) {
    // this.setElement(Document.get().createDivElement());
    Element heading = Document.get().createHElement(1);
    this.getElement().appendChild(heading);
    this.getElement().appendChild(container);
    heading.setInnerHTML(header);

    setStyleName(DEFAULT_STYLENAME);
  }

  /**
   * Creates a jumbotron with the given header and content.
   */
  public Jumbotron(String header, String content) {
    this(header, new HTMLPanel(ParagraphElement.TAG, content));
  }

  /**
   * Creates a jumbotron with the given header and content.
   */
  public Jumbotron(String header, Widget content) {
    this(header);
    setWidget(content);
  }

  @SuppressWarnings("deprecation")
  @Override
  protected com.google.gwt.user.client.Element getContainerElement() {
    return (com.google.gwt.user.client.Element) container;
  }

}
